package plugin.demo.shardingsphere.seata.utils;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: Qiao Hang
 * @CreateDate: 2021/4/22 下午2:56
 * @UpdateDate:
 * @Description:
 */
public class DBUtils {

    public static List<Map> convertList(ResultSet rs)throws SQLException {
        List list = new ArrayList();
        ResultSetMetaData md = rs.getMetaData();
        int columnCount = md.getColumnCount();
        while(rs.next()) {
            Map rowData = new HashMap();
            list.add(rowData);
            for(int i =1; i <= columnCount; i++)
                rowData.put(md.getColumnName(i), rs.getObject(i));
        }
        return list;
    }
}
